﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace mjRegister
{
    public partial class EMailBuild : Form
    {
        public EMailBuild()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.listBox1.Items.Clear();
            string gmail = this.textBox1.Text.Trim();
            if (!string.IsNullOrEmpty(gmail))
            {
                string[] g = gmail.Split('@');
                IterationBuildMail(string.Empty, g[0], g[1]);
            }
            else
                MessageBox.Show("不能为空！");
        }

        void IterationBuildMail(string prefixusername,string mailusername,string maildomain)
        {
            for (int i = 0; i < mailusername.Length-1; i++)
            {
                this.listBox1.Items.Add(string.Format("{0}{1}.{2}@{3}", prefixusername,mailusername.Substring(0, i + 1), mailusername.Substring(i + 1), maildomain));
                IterationBuildMail(string.Format("{0}{1}.", prefixusername,mailusername.Substring(0, i + 1)), mailusername.Substring(i + 1), maildomain);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string emailfile = Path.Combine(Application.StartupPath, "emails.txt");
            using (StreamWriter sw = new StreamWriter(Path.Combine(Application.StartupPath, "emails.txt"), false, Encoding.Default))
            {
                for (int i = 0; i < this.listBox1.Items.Count; i++)
                {
                    sw.WriteLine(this.listBox1.Items[i].ToString());
                }
            }
            MessageBox.Show(string.Format("写入完成，文件生成到：{0}",emailfile));
        }

        private void EMailBuild_Load(object sender, EventArgs e)
        {

        }
    }
}
